//
//  UIBarButtonItem+Extensions.swift
//  新浪微博
//
//  Created by ZJ on 2017/10/11.
//  Copyright © 2017年 zj. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    /// 创建UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize
    ///   - target: target
    ///   - action: action
    convenience init(title: String, fontSize: CGFloat = 16, target: AnyObject?, action: Selector, isBack: Bool = false) {
        let btn = UIButton()
        btn.setTitle(title, for: UIControlState.normal)
        btn.setTitle(title, for: UIControlState.highlighted)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        btn.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
        btn.setTitleColor(UIColor.orange, for: UIControlState.highlighted)
        btn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage.init(named: imageName), for: UIControlState.normal)
            btn.setImage(UIImage.init(named: imageName + "_highlighted"), for: UIControlState.highlighted)
        }
        
        btn.sizeToFit()
        
        self.init(customView: btn)
    }
}
